<script>
import map from "../assets/guangximap.json";
import mapData from "../assets/data.json";
export default {
  render: function (createElement) {
    return createElement("div", {
      attrs: {
        id: "guangximap",
      },
      style: {
        height: "600px",
      },
    });
  },
  data() {
    return {
      map,
      mapData,
      dataList: [],
    };
  },
  methods: {
    initEchart() {
      var name = '广西';
      echarts.registerMap(name,this.map)
      var myChart = echarts.init(document.getElementById("guangximap"));
      var option = {
        title:{
          text:'广西累计确诊'
        },
        tooltip: {
          //数据格式化
          formatter: function (params, callback) {
            return (
              params.seriesName + "<br />" + params.name + "：" + params.value
            );
          },
        },
        visualMap: {
          min: 0,
          max: 100,
          left: "left",
          top: "bottom",
          text: ["高", "低"], //取值范围的文字
          inRange: {
            color: ["#e0ffff", "red"], //取值范围的颜色
          },
          show: true, //图注
        },
        geo: {
          map: name,
          roam: false, //不开启缩放和平移
          zoom: 1.23, //视角缩放比例
          label: {
            normal: {
              show: true,
              fontSize: "10",
              color: "rgba(0,0,0,0.7)",
            },
          },
          itemStyle: {
            normal: {
              borderColor: "rgba(0, 0, 0, 0.2)",
            },
            emphasis: {
              areaColor: "yellow", //鼠标选择区域颜色
              shadowOffsetX: 0,
              shadowOffsetY: 0,
              shadowBlur: 20,
              borderWidth: 0,
              shadowColor: "rgba(0, 0, 0, 0.5)",
            },
          },
        },
        // 鼠标悬浮提示框
        series: [
          {
            name: "城市",
            type: "map",
            geoIndex: 0,
            data: this.dataList,
          },
        ],
      };
      myChart.setOption(option);
      myChart.on("click", function (params) {
        alert(params.name+'确诊人数为'+params.value);
      });
    },
    changeData() {
        let res = this.mapData.data.list[15].city.map((item) => {
          return {
            name: item.name+'市',
            value: item.conNum,
          };
        });
        this.dataList = res;
    }
  },
  mounted() {
    this.changeData();
    //绘制地图
    this.initEchart();
  },
};
</script>